home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / BM132A.LZH / bm_132a / keyboard.s < prev    next >
Encoding:
Text File  |  1995-07-06  |  2.7 KB  |  140 lines

  1. ikbd    equ    $118        ; keyboard vector
  2. key_ctl    equ    $fffffc00    ; keyboard control register
  3. key_dat    equ    $fffffc02    ; keyboard data register
  4.  
  5. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  6. * Initialise custom keyboard packet handler        *
  7. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  8. Initialise_ikbd:
  9.     lea    key_buffer,a0
  10.     moveq    #128/4-1,d7
  11. .clear_keybd:
  12.     clr.l    (a0)+
  13.     dbf    d7,.clear_keybd
  14.     bsr    Flush_ikbd
  15.     move.l    ikbd.w,old_ikbd
  16.     move.l    #ikbd_handler,ikbd.w
  17.     rts
  18.  
  19. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  20. * Remove custom keyboard packet handler            *
  21. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  22. Remove_ikbd:
  23.     bsr    Flush_ikbd
  24.     move.l    old_ikbd,ikbd.w
  25.     rts
  26.  
  27. old_ikbd:    ds.l    1
  28.  
  29. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  30. * Remove unread data from ikbd chip            *
  31. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  32. Flush_ikbd:
  33.     move.b    key_ctl.w,d0
  34.     btst    #0,d0
  35.     bne.s    read
  36.     rts
  37. read    move.b    key_dat.w,d0
  38.     bra.s    Flush_ikbd
  39.  
  40. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  41. * Keyboard Packet handler                *
  42. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  43. ikbd_handler:
  44.     movem.l    a0/d0-d1,-(sp)
  45.     move.b    key_ctl.w,d0
  46.     btst    #7,d0
  47.     beq.s    ikbd_aq
  48.     btst    #4,d0
  49.     bne.s    ik_err
  50.     btst    #5,d0
  51.     bne.s    ik_err
  52.     btst    #6,d0
  53.     bne.s    ik_err
  54.     btst    #0,d0
  55.     beq.s    ik_err
  56.     move.b    key_dat.w,d0
  57.  
  58.     cmp.b    #$ff,d0            ; joystick 1 packet
  59.     beq.s    do_joy1
  60.     cmp.b    #$fe,d0            ; joystick 0 packet
  61.     beq.s    do_joy0
  62.  
  63. mouse_event:
  64.     move.b    d0,d1
  65.     and.b    #$fc,d1            ; %111110xx = mouse packet 
  66.     cmp.b    #$f8,d1
  67.     bne.s    key_press
  68.     and.b    #3,d0
  69.     move.b    d0,buttons
  70.     move.l    #get_dx,ikbd.w
  71.     bra.s    ikbd_aq
  72.  
  73. do_joy0:
  74.     move.l    #get_joy0,ikbd.w
  75.     bra.s    ikbd_aq
  76.  
  77. do_joy1:
  78.     move.l    #get_joy1,ikbd.w
  79.     bra.s    ikbd_aq
  80.  
  81.  
  82. key_press:
  83.     btst    #7,d0            ; test release bit
  84.     seq    d1            ; d1.b cleared if release bit set
  85.     and.w    #$7f,d0            ; mask off release bit
  86.     lea    key_buffer,a0
  87.     move.b    d1,(a0,d0.w)
  88. ikbd_aq:
  89.     bclr    #6,$fffffa11.w
  90.     movem.l    (sp)+,a0/d0-d1
  91.     rte
  92.  
  93.  
  94. ik_err:    move.b    key_dat.w,d0
  95.     bra.s    ikbd_aq
  96.  
  97. get_dx:    move.l    d0,-(sp)
  98.     move.b    key_dat.w,d0
  99.     ext.w    d0
  100.     add    d0,mouse_dx
  101.     move.l    #get_dy,ikbd.w
  102.     move.l    (sp)+,d0
  103.     bclr    #6,$fffffa11.w
  104.     rte
  105.  
  106. get_dy:    move.l    d0,-(sp)
  107.     move.b    key_dat.w,d0
  108.     ext.w    d0
  109.     add    d0,mouse_dy
  110.     move.l    #ikbd_handler,ikbd.w
  111.     move.l    (sp)+,d0
  112.     bclr    #6,$fffffa11.w
  113.     rte
  114.  
  115.  
  116. get_joy1:
  117.     move.b    key_dat.w,joy0
  118.     move.l    #ikbd_handler,ikbd.w
  119.     bclr    #6,$fffffa11.w
  120.     rte
  121.  
  122. get_joy0:
  123.     move.b    key_dat.w,joy1
  124.     move.l    #ikbd_handler,ikbd.w
  125.     bclr    #6,$fffffa11.w
  126.     rte
  127.  
  128.     Section Bss
  129.  
  130. key_buffer:    ds.b    128
  131.  
  132. mouse_dx:    ds.w    1
  133. mouse_dy:    ds.w    1
  134.  
  135. joy0:        ds.b    1
  136. joy1:        ds.b    1
  137. buttons:    ds.b    1
  138.  
  139.     Section    Text
  140.